package org.thomias.exo1.tcp.agent;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.net.InetSocketAddress;
import java.net.Socket;

public class Client {
	public void send(String request) {
		try {
			Socket socket = new Socket();
			PrintStream out = null;
			BufferedReader in = null;

			try {
				socket.setReuseAddress(true);
				socket.connect(new InetSocketAddress("192.168.1.97", 22222),
						5000);
				out = new PrintStream(socket.getOutputStream());
				out.println(request);
				in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
				String response = in.readLine();
				println("Received from Server: " + response);

			} finally {
				if (out != null) {
					out.close();
				}
				
				try {
					in.close();
				} catch (Exception e) {
				}
				socket.close();
			}
		} catch (Exception e) {
		}
	}

	public static void println(String msg) {
		System.out.println(msg);
	}
}